import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import WindiCSS from 'vite-plugin-windicss'


// https://vitejs.dev/config/

import { resolve } from "path";
import { isPlusToken } from "typescript";

export default defineConfig({
  plugins: [vue(),WindiCSS(),

    // Element-plus按需引入配置
    AutoImport({
      imports:[
        'vue',
        'vue-router',
        'pinia'
      ],
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],

  // 别名路径定义
  base: './',
  resolve: {

    alias: {
      '@': resolve(__dirname, 'src'), 
    },
  },


  // 生产环境打包不显示console.log
  build: {
      minify: "terser",
      terserOptions: {
        compress: {
            //关闭打印信息
          drop_console: true,
          drop_debugger: true
        }
      }
    },

  // 服务器端口及代理配置
  server: {
    proxy: {
      '/dev-api': {
        target: "http://47.109.25.58:8079/proxy",
        changeOrigin: true,
        rewrite: (p) => p.replace(/^\/dev-api/, ''),
        bypass(req, res, options) {
          const proxyURL = options.target + options.rewrite(req.url);
          console.log('[proxy] %s %s %s', req.method, '-->', proxyURL);
        },
      },
    },
  },
  
});
